package com.new2i.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.new2i.model.DoctorEntity;
import com.new2i.model.ScreenDoctorEntity;
import com.new2i.service.able.PassportService; 
import com.new2i.util.Collection2JsonUtil;
import com.new2i.util.HttpSessionUtil;

/**
 * 通行证相应接口
 * 
 * @since 2015/09/04
 * @author 2i
 *
 */
@Controller
@RequestMapping("api/passport")
public class PassportApiAction extends BaseAction{

	@Autowired 
	private transient PassportService mPassportService; 
	  
	 
	/**
	 * 医生登录
	 * 
	 * @since 2015/09/04
	 * @author 2i
	 * @param request
	 * @param response
	 * @param doctor
	 */
	@RequestMapping("/login.action")
	public void doctorLogin(HttpServletRequest request,HttpServletResponse response,DoctorEntity doctor){ 
		HashMap<String, Object> map = mPassportService.doctorLogin(doctor); 
		//若成功返回数据
		if (!map.containsKey("code")) {
			HttpSessionUtil.saveDoctorToSession(request, map);
		}
		String value = Collection2JsonUtil.byObject(map);
		write2client(response, value);
	}
	 
	
	/**
	 * 客户端医生登录接口
	 * 
	 * @since 2015/09/22
	 * @author 2i
	 * @param request
	 * @param response
	 */
	@RequestMapping("/doctor/login.action") 
	public void ScreenDoctorLogin(HttpServletRequest request,HttpServletResponse response,ScreenDoctorEntity scDoctor){ 
		HashMap<String, Object> map = mPassportService.screenDoctorLogin(scDoctor); 
		String value = Collection2JsonUtil.byObject(map);
		write2client(response, value);
	}
	
	
	/**
	 * 注销接口
	 * 
	 * @since 2015/09/04
	 * @author 2i
	 * @param request
	 * @param response
	 */
	@RequestMapping("/logoff.action")
	public ModelAndView doctorLogin(HttpServletRequest request,HttpServletResponse response){
		HttpSessionUtil.logoff(request);
		return new ModelAndView("redirect:/");
	}
 
}
